<script setup lang='ts'>
import Button from '../../components/Button.vue';
import RightList from '../../components/RightList.vue';
import { ref, inject } from 'vue';
import { annotationObjectList, poiObjectList, effectObjectList, parkObjectList, ueObjectList, vectorObjectList } from './data';
import EsLocalSkyBox from './esObj/EsLocalSkyBox.vue'; //天空盒组件
import EsPipeFence from './esObj/EsPipeFence.vue'; //管道电子围栏组件
import EsAlarm from './esObj/EsAlarm.vue'; //报警组件
import EsApertureEffect from './esObj/EsApertureEffect.vue'; //光圈特效组件
import EsCameraVisibleRange from './esObj/EsCameraVisibleRange.vue'; //摄像头组件
import EsCar from './esObj/EsCar.vue'; //车辆组件
import EsGeoDiv from './esObj/EsGeoDiv.vue'; //管道电子围栏组件
import EsGeoLineString from './esObj/EsGeoLineString.vue'; //折线组件
import EsGeoPolygon from './esObj/EsGeoPolygon.vue'; //多边形组件
import EsGeoRectangle from './esObj/EsGeoRectangle.vue'; //矩形组件
import EsGltfModel from './esObj/EsGltfModel.vue'; //建筑组件
import EsHuman from './esObj/EsHuman.vue'; //人员组件
import EsImageLabel from './esObj/EsImageLabel.vue'; //图标点组件
import EsLocalCircle from './esObj/EsLocalCircle.vue'; //圆组件
import EsPath from './esObj/EsPath.vue'; //路径组件
import EsPolygonFence from './esObj/EsPolygonFence.vue'; //电子围栏组件
import EsTextLabel from './esObj/EsTextLabel.vue'; //文字标注组件
import EsUnrealActor from './esObj/EsUnrealActor.vue'; //UnrealActor
import EsDatasmithRuntimeModel from './esObj/EsDatasmithRuntimeModel.vue'; //UnrealActor
import EsLevelRuntimeModel from './esObj/EsLevelRuntimeModel.vue'; //UnrealActor
import EsVideoFusion from './esObj/EsVideoFusion.vue'; //视频融合组件
import EsWidget from './esObj/EsWidget.vue'; //部件组件
import EsPit from './esObj/EsPit.vue'; //坑组件
import EsPoi3D from './esObj/EsPoi3D.vue'; //ESPoi3D组件
import EsPoi2D from './esObj/EsPoi2D.vue'; //ESPoi2D组件
import EsPipeline from './esObj/EsPipeline.vue'; //管线组件
import EsDynamicWater from './esObj/EsDynamicWater.vue'; //局部水面组件
import EsGeoWater from './esObj/EsGeoWater.vue'; //地理水面组件
import EsEntityCluster from './esObj/EsEntityCluster.vue'; //poi聚合
import { SceneTree, SceneTreeItem } from "xbsj-xe2/dist-node/xe2";

import { XbsjEarthUi } from "../../scripts/xbsjEarthUi";
import { ESLevelRuntimeModel, ESDatasmithRuntimeModel } from 'esobjs-xe2-plugin/dist-node/esobjs-xe2-plugin-main';
import { createSceneObjTreeItemFromJson } from "../plotting/esObj/fun";
import { Message, messageBox } from "earthsdk-ui"
// 场景树
const sceneTree = inject('sceneTree') as SceneTree

const xbsjEarthUi = inject('xbsjEarthUi') as XbsjEarthUi
const create = (item: { zh: string, type: string, icon: string }) => {
    const viewer = xbsjEarthUi.activeViewer
    if (!viewer) return
    if (viewer.typeName !== 'ESUeViewer') {
        Message.warning('请在ue视口下操作')
        return
    }
    objType.value = item.type
    const sceneObject = xbsjEarthUi.createSceneObject(item.type) as ESDatasmithRuntimeModel | ESLevelRuntimeModel
    sceneObject.editing = true
    sceneObject.name = item.zh
    sceneObject.d(sceneObject.editingChanged.disposableOnce(() => {
        if (sceneObject.editing === false) {
            objType.value = ''
            const json = JSON.parse(sceneObject.jsonStr)
            xbsjEarthUi.destroySceneObject(sceneObject)
            createSceneObjTreeItemFromJson(xbsjEarthUi, json)
        }
    }))
}
const objType = ref<string>('')

const changeCheckedStatus = (sceneTreeItem:SceneTreeItem) => sceneTreeItem.uiTreeObject.check(sceneTreeItem.uiTreeObject.checkedStatus !== "checked")
const changeDelete = function() {
    messageBox({ text: '确认全部删除？' })
            .then(() => {
                // const ids = ['ae103185-08c7-4ed0-b6d4-15ad77bbbf66', 'd36f6fd5-119c-4c39-a3d8-6690fecede41', '30ad2bf5-1796-496a-9c8e-6cce9d5188f4', 'df2e3b8a-f075-4427-81a5-5e4c9966e43b', '98730a86-aa65-49b7-89e2-aef0aa308628', 'e0f4f354-89fb-487e-a262-9ecd8ee3007b']
                // 找出原先的 剩下的全部选中待删除
                sceneTree.uiTree.redrawInfo.middleTreeItems.forEach((item, index) => {
                    if (index > 5) {
                        console.log(1, 'iiii111', item.id);
                        changeCheckedStatus(item)
                    }
                })
                // sceneTree.sceneUiTree.clearAllSelectedItems()
                const list = [...sceneTree.selectedItems] //删除选中
                console.log(sceneTree, 'iiiiit++em', list);
                list.forEach(obj => {
                    if (obj.isDestroyed()) return
                    obj.detachFromParent()
                })
            })
            .catch(() => {})
}
</script>
<template>
    <RightList :title="'矢量'" :isTop="true">
        <Button v-for="item in vectorObjectList" :name="item.icon" :content="item.zh"
            :click="() => { objType === item.type ? objType = '' : objType = item.type }"
            :actived="objType === item.type" :left-button="item.leftButton"></Button>
        <EsGeoLineString v-if="objType === 'esGeoLineString'" @close="objType = ''"></EsGeoLineString>
        <EsGeoPolygon v-if="objType === 'esGeoPolygon'" @close="objType = ''"></EsGeoPolygon>
        <EsLocalCircle v-if="objType === 'esLocalCircle'" @close="objType = ''"></EsLocalCircle>
        <EsGeoRectangle v-if="objType === 'esGeoRectangle'" @close="objType = ''"></EsGeoRectangle>
    </RightList>
    <RightList :title="'注记'">
        <Button v-for="item in annotationObjectList" :name="item.icon" :content="item.zh"
            :click="() => { objType === item.type ? objType = '' : objType = item.type }"
            :actived="objType === item.type" :left-button="item.leftButton"></Button>
        <!-- <EsTextLabel v-if="objType === 'esTextLabel'" @close="objType = ''"></EsTextLabel> -->
        <EsImageLabel v-if="objType === 'esImageLabel'" @close="objType = ''"></EsImageLabel>
        <!-- <EsWidget v-if="objType === 'esWidget'" @close="objType = ''"></EsWidget> -->
        <!-- <EsGeoDiv v-if="objType === 'esGeoDiv'" @close="objType = ''"></EsGeoDiv> -->
        <!-- <EsPoi3D v-if="objType === 'esPoi3D'" @close="objType = ''"></EsPoi3D> -->
        <!-- <EsPoi2D v-if="objType === 'esPoi2D'" @close="objType = ''"></EsPoi2D> -->
        <!-- <EsEntityCluster v-if="objType === 'esEntityCluster'" @close="objType = ''"></EsEntityCluster> -->
    </RightList>
    <RightList :title="'图形'">
        <Button v-for="item in poiObjectList" :name="item.icon" :content="item.zh"
            :click="() => { objType === item.type ? objType = '' : objType = item.type }"
            :actived="objType === item.type" :left-button="item.leftButton"></Button>
            <EsPoi3D v-if="objType === 'esPoi3D'" @close="objType = ''"></EsPoi3D>
            <EsPoi2D v-if="objType === 'esPoi2D'" @close="objType = ''"></EsPoi2D>
    </RightList>
    <!-- <RightList :title="'园区'">
        <Button v-for="item in parkObjectList" :name="item.icon" :content="item.zh"
            :click="() => { objType === item.type ? objType = '' : objType = item.type }"
            :actived="objType === item.type" :left-button="item.leftButton"></Button>
        <EsHuman v-if="objType === 'esHuman'" @close="objType = ''"></EsHuman>
        <EsCar v-if="objType === 'esCar'" @close="objType = ''"></EsCar>
        <EsGltfModel v-if="objType === 'esGltfModel'" @close="objType = ''"></EsGltfModel>
    </RightList> -->
    <RightList :title="'特效'">
        <Button v-for="item in effectObjectList" :name="item.icon" :content="item.zh"
            :click="() => { objType === item.type ? objType = '' : objType = item.type }"
            :actived="objType === item.type" :left-button="item.leftButton"></Button>
        <EsPath v-if="objType === 'esPath'" @close="objType = ''"></EsPath>
        <EsApertureEffect v-if="objType === 'esApertureEffect'" @close="objType = ''"></EsApertureEffect>
        <EsPolygonFence v-if="objType === 'esPolygonFence'" @close="objType = ''"></EsPolygonFence>
        <EsPipeFence v-if="objType === 'esPipeFence'" @close="objType = ''"></EsPipeFence>
        <EsAlarm v-if="objType === 'esAlarm'" @close="objType = ''"></EsAlarm>
        <EsCameraVisibleRange v-if="objType === 'esCameraVisibleRange'" @close="objType = ''"></EsCameraVisibleRange>
        <EsVideoFusion v-if="objType === 'esVideoFusion'" @close="objType = ''"></EsVideoFusion>
        <EsLocalSkyBox v-if="objType === 'esLocalSkyBox'" @close="objType = ''"></EsLocalSkyBox>
        <EsPit v-if="objType === 'esPit'" @close="objType = ''"></EsPit>
        <EsPipeline v-if="objType === 'esPipeline'" @close="objType = ''"></EsPipeline>
        <EsDynamicWater v-if="objType === 'esDynamicWater'" @close="objType = ''"></EsDynamicWater>
        <EsGeoWater v-if="objType === 'esGeoWater'" @close="objType = ''"></EsGeoWater>
    </RightList>
    <!-- <RightList :title="'ue引擎'">
        <Button v-for="item in ueObjectList" :name="item.icon" :content="item.zh"
            :click="() => { objType === item.type ? objType = '' : objType = item.type }"
            :actived="objType === item.type" :left-button="item.leftButton"></Button>
        <EsUnrealActor v-if="objType === 'esUnrealActor'" @close="objType = ''"></EsUnrealActor>
        <EsDatasmithRuntimeModel v-if="objType === 'esDatasmithRuntimeModel'" @close="objType = ''">
        </EsDatasmithRuntimeModel>
        <EsLevelRuntimeModel v-if="objType === 'esLevelRuntimeModel'" @close="objType = ''"></EsLevelRuntimeModel>
    </RightList> -->
    <RightList>
        <Button :name="'shanchu'" :content="'全部删除'" :click="changeDelete" :left-button="false"></Button>
    </RightList>
</template>
